/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rw.table;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JTable;

/**
 *
 * @author Rene Tapia
 */
public class TableMouseListener extends MouseAdapter {

    private JTable table;

    public TableMouseListener(JTable table) {
        this.table = table;
    }

    @Override
    public void mouseClicked(MouseEvent e) {
        int col = table.columnAtPoint(e.getPoint());
        int row = table.rowAtPoint(e.getPoint());

        ATableModel tableModel = (ATableModel) table.getModel();

        if (tableModel.isCellEditableByClick(row, col)) {
            ATableAction action = tableModel.getEditableByClickAction(row, col);
            if (action == null) {
                throw new RuntimeException("La celda es editable por click pero no posee accion asociada");
            }
            action.actionPerformed(table, row, col);
        }

    }
}
